js location

85

js location -

// https://example.com:81/path?argument=value#hash

location.href         // https://example.com:81/path?argument=value#hash
location.protocol     // https
location.hostname     // example.com
location.port         // 81
location.host         // example.com:81
location.pathname     // /path
location.search       // ?argument=value       (see URLSearchParams to parse)
location.hash         // #hash
location.origin       // https://example.com"

how to use location.pathname -

// Let's an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/Location.pathname"> element be in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.pathname; // Returns:'/en-US/docs/Location.pathname'

Comments

Submit
0 Comments